home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / ace / c / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-04  |  7.0 KB  |  260 lines

  1. /* << ACE >>
  2.  
  3.    -- Amiga BASIC Compiler --
  4.  
  5.    ** Parser: standard output and screen printing code **
  6.    ** Copyright (C) 1998 David Benn
  7.    ** 
  8.    ** This program is free software; you can redistribute it and/or
  9.    ** modify it under the terms of the GNU General Public License
  10.    ** as published by the Free Software Foundation; either version 2
  11.    ** of the License, or (at your option) any later version.
  12.    **
  13.    ** This program is distributed in the hope that it will be useful,
  14.    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    ** GNU General Public License for more details.
  17.    **
  18.    ** You should have received a copy of the GNU General Public License
  19.    ** along with this program; if not, write to the Free Software
  20.    ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    Author: David J Benn
  23.      Date: 26th October-30th November, 1st-13th December 1991,
  24.        14th,20th-27th January 1992, 
  25.            2nd-17th, 21st-29th February 1992, 
  26.        1st,13th,14th,22nd,23rd March 1992,
  27.        21st,22nd April 1992,
  28.        2nd,3rd,11th,15th,16th May 1992,
  29.        7th,8th,9th,11th,13th,14th,28th,29th,30th June 1992,
  30.        2nd-8th,14th-19th,26th-29th July 1992,
  31.        1st-3rd,7th,8th,9th August 1992,
  32.        6th,7th,13th December 1992,
  33.        6th January 1993,
  34.        18th February 1993,
  35.        10th,11th,31st October 1993,
  36.        14th,15th December 1993,
  37.        2nd January 1994
  38. */
  39.  
  40. #include "acedef.h"
  41.  
  42. #define QUN_CODE 3
  43.  
  44. /* externals */
  45. extern    int    sym;
  46. extern    int    lastsym;
  47. extern    int    obj;
  48. extern    BOOL    end_of_source;
  49. extern    BOOL    dosused;
  50. extern    int      fstrcount;
  51.  
  52. /* functions */
  53. void gen_printcode(code)
  54. int code;
  55. {
  56.  switch(code)
  57.  {
  58.   /* LF */
  59.   case LF_CODE :     gen("move.l","#0","-(sp)");
  60.              break;
  61.   /* TAB */
  62.   case TAB_CODE :      gen("move.l","#1","-(sp)");
  63.             break;
  64.   /* SPACE */
  65.   case SPACE_CODE :    gen("move.l","#2","-(sp)");
  66.             break;  
  67.   /* QUN */
  68.   case QUN_CODE :    gen("move.l","#3","-(sp)");
  69.             break;    
  70.  }
  71.  
  72.  /* call function */
  73.  gen("jsr","_Ucodeprint","  ");
  74.  gen("addq","#4","sp");
  75.  enter_XREF("_Ucodeprint");
  76. }
  77.  
  78. void print_statement()
  79. {
  80. /* - Print expression(s) to a DOS or Intuition window.
  81.    - Expressions can be separated by spaces, commas or semicolons.
  82.    - Text is clipped at the right edge of an Intuition window, but
  83.      wraps around in a DOS window. The former is in line with AmigaBASIC.
  84.    - Both window-types scroll text when the bottom is reached.
  85. */  
  86. int exprtype,arguments=0;
  87.  
  88. enter_XREF("_GfxBase"); 
  89.  
  90. do
  91. {
  92.  if (sym != ident && !strfunc() && !numfunc() && !factorfunc() &&
  93.      obj != constant) 
  94.     insymbol();  /* ident/func/literal after space or as first parameter */
  95.  
  96.  /* PRINT# ? */
  97.  if (sym == hash && (lastsym == printsym || lastsym == question)) return;
  98.  
  99.  /* end of line, multi-statement, ";", "," ELSE or comment 
  100.     after PRINT command word? -> don't proceed to expr! */
  101.  if ((sym == endofline) || (sym == colon) || (sym == apostrophe) || 
  102.      (sym == semicolon) || (sym == comma) || (sym == elsesym) ||
  103.      (end_of_source))
  104.  {
  105.   if (sym == comma) gen_printcode(TAB_CODE);
  106.   else
  107.   if ((arguments == 0) && (sym != semicolon)) 
  108.      gen_printcode(LF_CODE);  /* PRINT with no args */ 
  109.  
  110.   if (sym != colon && sym != elsesym) 
  111.      insymbol();  /* leave colon for multi-statement 
  112.              in statement() or leave ELSE for if_statement() */
  113.   return;
  114.  }
  115.  
  116.   /* get an expression */
  117.   exprtype = expr();
  118.    
  119.   if (exprtype == undefined) { _error(0); return; } /* illegal syms? */
  120.  
  121.   switch(exprtype)
  122.   {
  123.    case shorttype :  make_long();
  124.              gen("jsr","_Ushortprint","  ");
  125.              gen("addq","#4","sp");    
  126.              enter_XREF("_Ushortprint");
  127.              break;
  128.  
  129.    case longtype :   gen("jsr","_Ulongprint","  ");
  130.              gen("addq","#4","sp");    
  131.              enter_XREF("_Ulongprint");
  132.              break;
  133.  
  134.    case singletype : gen("jsr","_Usingleprint","  ");
  135.              gen("addq","#4","sp");    
  136.              enter_XREF("_Usingleprint");
  137.              break;
  138.  
  139.    case stringtype : gen("jsr","_Ustringprint","  ");
  140.              gen("addq","#4","sp");    
  141.              enter_XREF("_Ustringprint");
  142.              break;
  143.   }
  144.  
  145.   if (exprtype != stringtype) gen_printcode(SPACE_CODE); /* trailing space
  146.                                 for any number */
  147.   arguments++;
  148.  
  149.   if (sym == comma) gen_printcode(TAB_CODE);
  150.    
  151.  }
  152.  while ((sym == comma) || (sym == semicolon) || (sym == ident) ||
  153.     strfunc() || numfunc() || factorfunc() || obj == constant);  
  154.  
  155.  /* no comma or semicolon at end of PRINT -> LF */
  156.  gen_printcode(LF_CODE);
  157.  
  158.  /* need mathffp.library for _Usingleprint and 
  159.     _beep if called by _Ustringprint. 
  160.  */ 
  161.  enter_XREF("_MathBase");
  162. }  
  163.  
  164. void gen_printscode(code)
  165. int code;
  166. {
  167.  switch(code)
  168.  {
  169.   /* LF */
  170.   case LF_CODE :     gen("jsr","_printsLF","  ");
  171.               enter_XREF("_printsLF");
  172.              break;
  173.   /* TAB */
  174.   case TAB_CODE :      gen("jsr","_printsTAB","  ");
  175.              enter_XREF("_printsTAB");
  176.             break;
  177.   /* SPACE */
  178.   case SPACE_CODE :    gen("jsr","_printsSPC","  ");
  179.              enter_XREF("_printsSPC");
  180.             break;
  181.  }
  182. }
  183.  
  184. void prints_statement()
  185. {
  186. /* - print expression(s) to current rastport (intended for screens or
  187.      Intuition windows).
  188.    - expressions can be separated by spaces, commas or semicolons which
  189.      have the same effect as in the PRINT statement.
  190. */  
  191. int exprtype,arguments=0;
  192.  
  193. enter_XREF("_GfxBase"); 
  194.  
  195. do
  196. {
  197.  if (sym != ident && !strfunc() && !numfunc() && !factorfunc() &&
  198.      obj != constant) 
  199.     insymbol();  /* ident/func/literal after space or as first parameter */
  200.  
  201.  /* end of line, multi-statement, ";", "," ELSE or comment 
  202.     after PRINTS command word? -> don't proceed to expr! */
  203.  if ((sym == endofline) || (sym == colon) || (sym == apostrophe) || 
  204.      (sym == semicolon) || (sym == comma) || (sym == elsesym) ||
  205.      (end_of_source))
  206.  {
  207.   if (sym == comma) gen_printscode(TAB_CODE);
  208.   else
  209.   if ((arguments == 0) && (sym != semicolon)) 
  210.      gen_printscode(LF_CODE);  /* PRINTS with no args */ 
  211.  
  212.   if (sym != colon && sym != elsesym) 
  213.      insymbol();  /* leave colon for multi-statement 
  214.              in statement() or leave ELSE for if_statement() */
  215.   return;
  216.  }
  217.  
  218.   /* get an expression */
  219.   exprtype = expr();
  220.    
  221.   if (exprtype == undefined) { _error(0); return; } /* illegal syms? */
  222.  
  223.   switch(exprtype)
  224.   {
  225.    case shorttype :  gen("move.w","(sp)+","d0");
  226.              gen("jsr","_shortprints","  ");
  227.              enter_XREF("_shortprints");
  228.              break;
  229.  
  230.    case longtype :   gen("move.l","(sp)+","d0");  
  231.              gen("jsr","_longprints","  ");
  232.              enter_XREF("_longprints");
  233.              break;
  234.  
  235.    case singletype : gen("move.l","(sp)+","d0");
  236.              gen("jsr","_singleprints","  ");
  237.              enter_XREF("_singleprints");
  238.              enter_XREF("_MathBase");
  239.              break;
  240.  
  241.    case stringtype : gen("movea.l","(sp)+","a0");
  242.              gen("jsr","_stringprints","  ");
  243.              enter_XREF("_stringprints");
  244.              break;
  245.   }
  246.  
  247.   if (exprtype != stringtype) gen_printscode(SPACE_CODE); /* trailing space
  248.                                  for any number */
  249.   arguments++;
  250.  
  251.   if (sym == comma) gen_printscode(TAB_CODE);
  252.    
  253.  }
  254.  while ((sym == comma) || (sym == semicolon) || (sym == ident) ||
  255.     strfunc() || numfunc() || factorfunc() || obj == constant);  
  256.  
  257.  /* no comma or semicolon at end of PRINTS -> LF */
  258.  gen_printscode(LF_CODE);
  259. }  
  260.